
/***
 * @Description: 主要负责的是basic文件下的基础功能测试的C语言文
 * @Author: Liverpool
 * @Date: 2024-02-16 23:12:07
 * @LastEditTime: 2024-02-16 23:29:23
 * @LastEditors: Liverpool
 */
#include "basic_text.h"

/***
 * @description: basic基础功能测试
 * @Author: Liverpool
 * @Date: 2024-02-16 23:34:52
 * @return {*}
 */
void basic_text(void)
{
    // list_text();
    // memory_block_text();
    // timer_text();
}
/***
 * @description: 链表功能测试
 * @Author: Liverpool
 * @Date: 2024-02-16 23:35:57
 * @return {*}
 */
typedef struct _list_text
{
    int id;
    D_ListNode node;
} D_list_text;
void list_text(void)
{
#define Node_Count 4
    D_list_text node[Node_Count];
    D_List list;
    list_init(&list);
    for (int i = 0; i < Node_Count; i++)
    {
        node[i].id = i;
        list_insert_first(&list, &node[i].node);
    }
    plat_printf("...list insert...\n");
    D_ListNode *p;
    list_for_each_node(p, &list)
    {
        D_list_text *node_text = list_entry(p, D_list_text, node);
        plat_printf("%d\n", node_text->id);
    }
    plat_printf("remove first\n");
    for (int i = 0; i < Node_Count; i++)
    {
        p = list_remove_first(&list);
        plat_printf("id:%d\n", list_entry(p, D_list_text, node)->id);
    }

    list_init(&list);
    for (int i = 0; i < Node_Count; i++)
    {
        list_insert_last(&list, &node[i].node);
    }
    plat_printf("...list insert...\n");
    list_for_each_node(p, &list)
    {
        D_list_text *node_text = list_entry(p, D_list_text, node);
        plat_printf("%d\n", node_text->id);
    }
    plat_printf("remove last\n");
    for (int i = 0; i < Node_Count; i++)
    {
        p = list_remove_last(&list);
        plat_printf("id:%d\n", list_entry(p, D_list_text, node)->id);
    }
    plat_printf("insert after\n");
    for (int i = 0; i < Node_Count; i++)
    {
        list_insert_after(&list, list_get_first(&list), &node[i].node);
    }
    list_for_each_node(p, &list)
    {
        D_list_text *node_text = list_entry(p, D_list_text, node);
        plat_printf("%d\n", node_text->id);
    }
}

/***
 * @description: 内存管理模块测试
 * @Author: Liverpool
 * @Date: 2024-02-25 01:21:44
 * @return {*}
 */
void memory_block_text(void)
{
    D_MemoryBlock blocklist;        // 内存块链表
    static uint8_t buffer[10][100]; // 可以分配的结构性数组
    memory_block_init(&blocklist, buffer, 100, 10, Locker_Thread);
    void *temp[10];
    for (int i = 0; i < 10; i++)
    {
        temp[i] = memory_block_alloc(&blocklist, 0);
        plat_printf("block_node:%p,free_count:%d\n", temp[i], memory_block_free_cnt(&blocklist));
    }
    for (int i = 0; i < 10; i++)
    {
        memory_block_free(&blocklist, temp[i]);
        plat_printf("free_count:%d\n", memory_block_free_cnt(&blocklist));
    }

    memory_block_destroy(&blocklist);
}
void timer0_proc(struct _net_timer_t *timer, void *arg)
{
    static int count1 = 1;
    plat_printf("this is %s:%d\n", timer->name, count1++);
}
void timer1_proc(struct _net_timer_t *timer, void *arg)
{
    static int count2 = 1;
    plat_printf("this is %s:%d\n", timer->name, count2++);
}
void timer2_proc(struct _net_timer_t *timer, void *arg)
{
    static int count3 = 1;
    plat_printf("this is %s:%d\n", timer->name, count3++);
}
void timer3_proc(struct _net_timer_t *timer, void *arg)
{
    static int count4 = 1;
    plat_printf("this is %s:%d\n", timer->name, count4++);
}
/***
 * @description: 用来测试定时器的相关功能
 * @Author: Liverpool
 * @Date: 2024-05-29 00:27:18
 * @return {*}
 */
void timer_text(void)
{
    static D_Net_timer t0, t1, t2, t3;
    net_timer_add(&t0, "t0", timer0_proc, (void *)0, 200, 0);
    net_timer_add(&t1, "t1", timer1_proc, (void *)0, 1000, NET_TIMER_RELOAD);
    net_timer_add(&t2, "t2", timer2_proc, (void *)0, 1000, NET_TIMER_RELOAD);
    net_timer_add(&t3, "t3", timer3_proc, (void *)0, 4000, NET_TIMER_RELOAD);
    net_timer_remove(&t0);
    // net_timer_check_tmo(100);
    // net_timer_check_tmo(1200);
    // net_timer_check_tmo(2000);
}